package com.xiaohai.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xiaohai.exception.CustomException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName:ExcelListener
 * Package:IntelliJ IDEA
 * Description:
 * Author 何诗海
 *
 * @Create 2024/3/5 20:41
 * @Version 1.0
 */
@Slf4j
public class ExcelListener<T> extends AnalysisEventListener<T> {

    private final List<T> dataList = new ArrayList<>();

    @Override
    public void invoke(T data, AnalysisContext context) {
        dataList.add(data);
    }

    @Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
       throw new CustomException(exception.getMessage());
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
    }

    public List<T> getDatas() {
        return dataList;
    }
}